<template>
  <slot></slot>
  <div
      style="width: 100%;height: 100%;"
      ref="container"
  ></div>
</template>

<script setup>
import {useInit} from './init'
import {onMounted, ref, nextTick, onUpdated, watch} from 'vue'
import useEditorStore from './store/editor'
import HandleClass from "./handle/handleClass.js";

const props=defineProps({
  codeType:String
})

const container = ref(null)
let monacoEditor
let editorHandle
onMounted(() => {
  //初始化
  monacoEditor = useInit(container,props.codeType)
  editorHandle = new HandleClass(monacoEditor)

  const editorContent = editorHandle.getValue()
  const editorStore = useEditorStore()
  editorStore.setEditorContent(editorContent)
  editorHandle.revealLine(30)
})

/*暴露函数*/
defineExpose({
  monacoEditor: () => monacoEditor, //把monacoEditor对象暴露给父组件
  ...editorHandle,
  editorHandle: () => editorHandle, //吧monacoEditor操作函数暴露给父组件
  getValue:()=>editorHandle.getValue(),
  setValue:(v)=>editorHandle.setValue(v)
});

</script>

<style scoped>

</style>
